package com.yc.taixin.support.utils;

import java.util.*;

/*
用来存放程序中重用的代码
author: yc
time: 2020-6-11 15:02:57
命名格式: xxx_yc
 */
public class NoImportUtil {
	//预约时间的"ii"初始化map
	public Map<Integer, String> yuyueIiMap_yc() {
		return new HashMap<Integer, String>() {{
			put(0, "08:00-09:00");
			put(1, "09:00-10:00");
			put(2, "10:00-11:00");
			put(3, "11:00-12:00");
			put(4, "13:30-14:30");
			put(5, "14:30-15:30");
			put(6, "15:30-16:30");
			put(7, "16:30-17:30");
		}};
	}

	//预约服务项目初始化map
	public static Map<Integer, String> serverItemMap_yc() {
		return new HashMap<Integer, String>() {{
			this.put(1, "上门取车代检-200.00");
			put(2, "到店检车预约-100.00");
			put(3, "免检车辆办理-60.00");
		}};
	}

	//获取当前月的前N个月份 -工具
	public String[] getMonth_yc(int number) {
		String[] lastMonths = new String[number];
		Calendar cal = Calendar.getInstance();
		//如果当前日期大于二月份的天数28天或者29天会导致计算月份错误，会多出一个三月份，故设置一个靠前日期解决此问题
		cal.set(Calendar.DAY_OF_MONTH, 1);
		for (int i = 0; i < number; i++) {
			int month = cal.get(Calendar.MONTH) + 1;
			lastMonths[(number - 1) - i] = cal.get(Calendar.YEAR) + "-" + (month < 10 ? "0" + month : month);
			cal.set(Calendar.MONTH, cal.get(Calendar.MONTH) - 1); //逐次往前推1个月
		}
		return lastMonths;
	}

	/**
	 * 获取x个周一到周五的日期
	 * @param count  个数
	 * @param pattern yyyy-mm-ss "yyyy-MM-dd E"
	 * @return
	 */
	public List<String> getWeekDay_yc(Integer count,String pattern) {
		Calendar calendar = Calendar.getInstance();
		Date[] dates = new Date[count];
		for (int i = 0; i < count; i++) {
			if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {//SUNDAY
				--i;
				calendar.add(Calendar.DAY_OF_WEEK, +1);
				continue;
			}
			dates[i] = calendar.getTime();
			calendar.add(Calendar.DATE, 1);
		}
		List<String> list=new ArrayList<>();
		for (Date date : dates) {
			list.add(DateUtil.format(date,pattern));
		}
		return list;
	}

}
